
const defaultState = {
    inputVal: 'hello, react-redux',
    list:[]
}

let reducer = (state = defaultState, action) => {
     
    if (action.type === 'inputChange') {
        let newState = JSON.parse(JSON.stringify(state))
        newState.inputVal = action.value
        
        return newState
    }
    if (action.type === 'addItem') {
		let newState = JSON.parse(JSON.stringify(state))
		newState.list.push(newState.inputVal)
		newState.inputVal = ''
		return newState
    }
    if (action.type === 'delItem') {
        let newState = JSON.parse(JSON.stringify(state))
        newState.list.splice(action.value, 1)
        	return newState
    }
 
        return state
}
export default reducer